﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Honestysoft.Baseframework.Model;
using Honestysoft.Baseframework.WebUI;
using System.IO;

namespace Honestysoft.Financing.WebUI.Module.Project
{
    public partial class ProjectOverview : System.Web.UI.Page
    {
        protected string _FilePath = "";

        protected string _UploadPath = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Sys_Attachment obj = new Utils().GetOverview(Request.QueryString["ID"]);
                if (obj == null)
                {
                    try
                    {
                        obj = CreateNewFile();
                    }
                    catch (Exception ex)
                    {
                        Honestysoft.BaseLibrary.ExceptionHandling.ExceptionHelper.ExceptionDistribute(ex, false);
                        Honestysoft.BaseLibrary.Logging.LoggingHelper.WriteLog(ex.Message);
                    }
                }
                if (obj == null)
                {
                    ScriptHelper.Window.AlertClose("无法从模板创建项目简介文档！模板文件不存在！");
                    return;
                }
                _FilePath = obj.Path + "/" + obj.FileName + "." + obj.Extension;
                _UploadPath = obj.Path;
                //_FilePath = "http://" + Request.Url.Host + ":" + Request.Url.Port + "/SCKJ/" + obj.Path + "/" + obj.FileName + "." + obj.Extension;
                //_UploadPath = "http://" + Request.Url.Host + ":" + Request.Url.Port + "/SCKJ/" + obj.Path;
            }
        }

        private Sys_Attachment CreateNewFile()
        {
            Sys_Attachment obj = new Utils().CreateOverviewBlank(Request.QueryString["ID"], UserLoginer.LoginUser.ID);
            new Honestysoft.BaseObject.BaseBusinessLogic<Sys_Attachment>(Globals.CurrentConnStringName).CreateEntity(obj);
            return obj;
        }
    }
}